package com.jeff.tianti.cms.service;

import com.jeff.tianti.cms.dao.ActivityAlertsDao;
import com.jeff.tianti.cms.dto.ActivityAlertsQueryDTO;
import com.jeff.tianti.cms.dto.font.ActivityAlertsTo;
import com.jeff.tianti.cms.entity.ActivityAlerts;
import com.jeff.tianti.common.entity.PageModel;
import com.jeff.tianti.common.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author xujianfang
 * @desc ActivityAlertsService��
 * @date 2019-07-11
 */
@Service
public class ActivityAlertsService extends CommonService<ActivityAlerts, String> {

    @Autowired
    private ActivityAlertsDao activityAlertsDao;

    @Autowired
    public void setActivityAlertsDao(ActivityAlertsDao activityAlertsDao) {
        super.setCommonDao(activityAlertsDao);
    }

    public PageModel<ActivityAlerts> queryActivityAlertsPage(ActivityAlertsQueryDTO activityAlertsQueryDTO) {
        return this.activityAlertsDao.queryActivityAlertsPage(activityAlertsQueryDTO);
    }

    public List<Map<String, Object>> queryActivityAlertsList(ActivityAlertsQueryDTO activityAlertsQueryDTO) {
        return this.activityAlertsDao.queryActivityAlertsList(activityAlertsQueryDTO);
    }

    public List<Map<String, Object>> queryActivityAlertsTitleList(ActivityAlertsQueryDTO activityAlertsQueryDTO) {
        return this.activityAlertsDao.queryActivityAlertsTitleList(activityAlertsQueryDTO);
    }


    public Page<ActivityAlerts> findAllNodel(Pageable pageable) {
        return this.activityAlertsDao.findAllNoDel(pageable);
    }

    public Page<ActivityAlerts> findByTo(ActivityAlertsTo actTo) {
        Pageable pageable = new PageRequest(actTo.getCurrentPage(), actTo.getPageSize(), Sort.Direction.DESC, "createDate");
        if ("2".equals(actTo.getType())) {
            return activityAlertsDao.findByToOrderByTime(actTo.getState(), actTo.getType(), pageable);
        }
        return activityAlertsDao.findByTo(actTo.getState(), actTo.getType(), pageable);
    }

    public ActivityAlerts findMaxSort() {
      return   activityAlertsDao.findMaxSort();
    }
}